#ifndef _FGL_H_
#define _FGL_H_

#include "vm.h"

typedef u8 GLenum;
typedef s8 GLint;
typedef u8 GLsizei;
typedef s32 GLfloat;
typedef s64 GLdouble;
typedef u8 GLboolean;

#define GLFLOAT_SHIFT 8
#define GLFLOAT(x) ((GLfloat)((x)*(1<<GLFLOAT_SHIFT)))

#define GLFLOAT_ONE		(1<<GLFLOAT_SHIFT)


inline GLfloat GLmul(GLfloat a, GLfloat b)
{
	return (GLfloat)((((GLdouble)a)*((GLdouble)b))>>GLFLOAT_SHIFT);
}

inline GLfloat GLdiv(GLfloat a, GLfloat b)
{
	return (GLfloat)(((((GLdouble)a)<<(GLFLOAT_SHIFT+GLFLOAT_SHIFT))/((GLdouble)b))>>GLFLOAT_SHIFT);
}

inline GLfloat GLabs(GLfloat a)
{
	if (a<0)
		return -a;
	return a;
}

enum //for glBegin
{
	GL_POINTS = 1,
	GL_LINES,
	GL_LINE_STRIP,
	GL_LINE_LOOP,
	GL_TRIANGLES,
	GL_TRIANGLE_STRIP,
	GL_TRIANGLE_FAN,
	GL_QUADS,
	GL_QUAD_STRIP,
	GL_POLYGON
};

enum //for glGetError
{
	GL_NO_ERROR = 0,
	GL_INVALID_ENUM,
	GL_INVALID_VALUE,
	GL_INVALID_OPERATION,
	GL_STACK_OVERFLOW,
	GL_STACK_UNDERFLOW,
	GL_OUT_OF_MEMORY,
	GL_TABLE_TOO_LARGE
};

enum //for glHint
{
	GL_DONT_CARE = 0,
	GL_FASTEST,
	GL_NICEST
};

enum //for glHint
{
	GL_FOG_HINT,
	GL_GENERATE_MIPMAP_HINT,
	GL_LINE_SMOOTH_HINT,
	GL_PERSPECTIVE_CORRECTION_HINT,
	GL_POINT_SMOOTH_HINT,
	GL_POLYGON_SMOOTH_HINT,
	GL_TEXTURE_COMPRESSION_HINT
};

enum //for glEnable/glDisable/glIsEnabled
{
	GL_ALPHA_TEST,
	GL_BLEND,
	GL_CULL_FACE,
	GL_DEPTH_TEST,
	GL_FOG,
	GL_NORMALIZE,
	GL_RESCALE_NORMAL,
	GL_TEXTURE_1D,
	GL_TEXTURE_2D
};

enum //for glCullFace
{
	GL_FRONT,
	GL_BACK,
	GL_FRONT_AND_BACK
};


GLenum glGetError();
void glBegin(GLenum mode);
void glEnd();
void glHint(GLenum target, GLenum mode);
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
void gluOrtho2D(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top);
void glFlush();
void glEnable(GLenum cap);
void glDisable(GLenum cap);
GLboolean glIsEnabled(GLenum cap);
void glCullFace(GLenum mode);
void glVertex2f(GLfloat x, GLfloat y);
void glVertex3f(GLfloat x, GLfloat y, GLfloat z);

#endif //_FGL_H_